#include <bits/stdc++.h>
#define MAXN 100005
using namespace std;
int n,m,a[MAXN],c[MAXN],d[30][30],t,x[4],A[300];

int main()
{
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);

    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=m;i++) scanf("%d",&c[i]);
    int K=ceil(log2(n));
    for(int i=1;i<=K;i++){
        for(int j=1;j<=1<<K-j;j++){
            char ch;
            cin>>ch;
            d[i][j]=ch-'0';
        }
    }

    scanf("%d",&t);
    for(int i=1;i<=t;i++){
        for(int j=0;j<4;j++) scanf("%d",&x[j]);
        for(int i=1;i<=c[i];i++){
            if(rand()%2) A[i]+=c[i];
        }
        printf("%d\n",A[i]);
    }
    return 0;
}